from django import forms



class PasswdForm(forms.Form):
    """
    login form data
    """
    Oldpasswd = forms.CharField(label='密码', max_length=20, min_length=6,
                               error_messages={"min_length": "密码长度要大于6", "max_length": "密码长度要小于20",
                                               "required": "密码不能为空"})
    Passwd = forms.CharField(label='密码', max_length=20, min_length=6,
                                error_messages={"min_length": "密码长度要大于6", "max_length": "密码长度要小于20",
                                                "required": "密码不能为空"})
    Password_repeat = forms.CharField(label='密码', max_length=20, min_length=6,
                                error_messages={"min_length": "密码长度要大于6", "max_length": "密码长度要小于20",
                                                "required": "密码不能为空"})

    def clean(self):
        """

        :return:
        """
        # 1、获取清洗之后的参数
        cleaned_data = super().clean()

        Oldpasswd = cleaned_data.get('Oldpasswd')
        Passwd = cleaned_data.get('Passwd')
        Password_repeat = cleaned_data.get('Password_repeat')

        # 2、判断新旧密码是否一致
        if Oldpasswd == Passwd:
            raise forms.ValidationError("新旧密码一致，请重新输入")
        # 3、判断两次输入的密码是否一致
        if Passwd != Password_repeat:
            raise forms.ValidationError("两次输入的密码不一致，请重新输入")

class SuperForm(forms.Form):
    """
    login form data
    """

    Passwd = forms.CharField(label='密码', max_length=20, min_length=6,
                                error_messages={"min_length": "密码长度要大于6", "max_length": "密码长度要小于20",
                                                "required": "密码不能为空"})

    def clean(self):
        """

        :return:
        """
        # 1、获取清洗之后的参数
        cleaned_data = super().clean()
        Passwd = cleaned_data.get('Passwd')

